﻿<template>
  <a-modal
    title="新增优惠详情"
    :width="900"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleSubmit"
    @cancel="handleCancel">
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
        <a-form-item label="单据号 " :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入单据号 " v-decorator="['rcptNo']" />
        </a-form-item>
        <a-form-item label="结算ID " :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入结算ID " v-decorator="['primaryId']" />
        </a-form-item>
        <a-form-item label="就诊编号 " :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入就诊编号 " v-decorator="['visitCode']" />
        </a-form-item>
        <a-form-item label="就诊卡号 " :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入就诊卡号 " v-decorator="['visitIcCode']" />
        </a-form-item>
        <a-form-item label="支付卡号 " :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入支付卡号 " v-decorator="['payIcCode']" />
        </a-form-item>
        <a-form-item label="套餐编码 " :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入套餐编码 " v-decorator="['packageCode']" />
        </a-form-item>
        <a-form-item label="套餐名称 " :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入套餐名称 " v-decorator="['packageName']" />
        </a-form-item>
        <a-form-item label="标准金额 " :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入标准金额 " v-decorator="['packageStandardAmount']" />
        </a-form-item>
        <a-form-item label="处方金额 " :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入处方金额 " v-decorator="['packagePrescriptCost']" />
        </a-form-item>
        <a-form-item label="一口价 享受的待遇一口价 " :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入一口价 享受的待遇一口价 " v-decorator="['packageTreatmentAmount']" />
        </a-form-item>
        <a-form-item label="享受一口价折扣 " :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入享受一口价折扣 " v-decorator="['packageTreatmentRebate']" />
        </a-form-item>
        <a-form-item label="" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入" v-decorator="['rebateInfoId']" />
        </a-form-item>
        <a-form-item label="" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入" v-decorator="['rebateInfoCategoy']" />
        </a-form-item>
        <a-form-item label="" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入" v-decorator="['treatmentDescribe']" />
        </a-form-item>
        <a-form-item label="" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入" v-decorator="['remark']" />
        </a-form-item>
        <a-form-item label="" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入" v-decorator="['cancelFlag']" />
        </a-form-item>
        <a-form-item label="结算折扣 " :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入结算折扣 " v-decorator="['chargeRebate']" />
        </a-form-item>
        <a-form-item label="结算金额 " :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入结算金额 " v-decorator="['chargeCosts']" />
        </a-form-item>
        <a-form-item label="积分数量 " :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入积分数量 " v-decorator="['points']" />
        </a-form-item>
        <a-form-item label="积分类别 1 老带新 奖励及使用 2账户积分余额 " :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入积分类别 1 老带新 奖励及使用 2账户积分余额 " v-decorator="['pointType']" />
        </a-form-item>
        <a-form-item label="空、 null、1已收费 2 已退费  " :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入空、 null、1已收费 2 已退费  " v-decorator="['status']" />
        </a-form-item>
      </a-form>
    </a-spin>
  </a-modal>
</template>

<script>
  import {
    OutpBillItemsRebateAdd
  } from '@/api/modular/main/OutpBillItemsRebateManage'

  export default {
    data () {
      return {
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 }
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 15 }
        },
        visible: false,
        confirmLoading: false,
        form: this.$form.createForm(this)
      }
    },
    methods: {
      // 初始化方法
      add (record) {
        this.visible = true
      },
      /**
       * 提交表单
       */
      handleSubmit () {
        const { form: { validateFields } } = this
        this.confirmLoading = true
        validateFields((errors, values) => {
          if (!errors) {
            for (const key in values) {
              if (typeof (values[key]) === 'object') {
                values[key] = JSON.stringify(values[key])
              }
            }
            OutpBillItemsRebateAdd(values).then((res) => {
              if (res.success) {
                this.$message.success('新增成功')
                this.confirmLoading = false
                this.$emit('ok', values)
                this.handleCancel()
              } else {
                this.$message.error('新增失败：' + JSON.stringify(res.message))
              }
            }).finally((res) => {
              this.confirmLoading = false
            })
          } else {
            this.confirmLoading = false
          }
        })
      },
      handleCancel () {
        this.form.resetFields()
        this.visible = false
      }
    }
  }
</script>
